<template>
  <el-container>
    <el-header style="background-color: #b3c0d1;
  color: #333;line-height:60px">欢迎使用电商后台管理系统</el-header>
    <el-container>
      <!-- 右侧菜单栏 -->
      <el-aside
        :width="isCollapse ? '64px' : '200px'"
        style="background-color: rgb(238, 241, 246);overflow-x:hidden"
      >
        <div
          class="toggle-button"
          @click="toggleCollapse"
        >|||</div>
        <el-menu
          active-text-color="#409EFF"
          :collapse=isCollapse
          collapse-transition
        >
          <el-menu-item
            @click=toPath(route.path)
            v-for="route in navRouters"
            :key="route.path"
            :index=route.path
          ><i :class=route.icon></i><span class="nav-name">{{route.name}}</span></el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { routes } from '../../router'
export default {
  data () {
    return {
      navRouters: [],
      isCollapse: false
    }
  },
  created () {
    routes.filter(route => {
      if (route.children) {
        route.children.filter(item => {
          if (item.meta.isNav) {
            this.navRouters.push(item)
          }
        }
        )
      }
    })
  },
  methods: {
    // 点击按钮切换菜单的折叠与展开
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    // 跳转
    toPath (path) {
      this.$router.push(path)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-aside {
  color: #333;
}
.nav-name {
  padding-left: 15px;
}
.toggle-button {
  background-color: #a4a7ab;
  font-size: 10px;
  line-height: 20px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
